package org.darcy.config;

import java.util.concurrent.Executors;

import org.darcy.service.init.InitSqlService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.scheduling.annotation.SchedulingConfigurer;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.scheduling.config.ScheduledTaskRegistrar;


@Configuration
@EnableScheduling
public class ScheduleConfig implements SchedulingConfigurer {

    @Override
    public void configureTasks(ScheduledTaskRegistrar taskRegistrar) {
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        executor.setMaxPoolSize(10);
        executor.setThreadNamePrefix("scheduled@");
        int corePoolSize = 5;
        taskRegistrar.setScheduler(Executors.newScheduledThreadPool(corePoolSize, executor));
    }
    
    @Autowired
    private InitSqlService InitSqlService;

    /**
     * 每天凌晨三天清理数据
     */
    @Scheduled(cron = "0 0 3 * * ?")
    public void dailyTask() {
    	InitSqlService.dailyTask();
    }

}
